<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OSS Image Upload</title>
</head>
<body>
<h1>Upload Image to OSS</h1>
<input type="file" id="fileInput" accept="image/*">
<button id="uploadButton">Upload</button>
<div id="result"></div>

<script>
    document.getElementById('uploadButton').addEventListener('click', function() {
        const fileInput = document.getElementById('fileInput');
        const file = fileInput.files[0];

        if (!file) {
            alert('Please select a file first.');
            return;
        }

        const formData = new FormData();
        formData.append('file', file);

        fetch('/upload', {
            method: 'POST',
            body: formData
        })
            .then(response => response.json())
            .then(data => {
                document.getElementById('result').innerText = 'File uploaded successfully: ' + data.url;
            })
            .catch(error => {
                document.getElementById('result').innerText = 'Error uploading file: ' + error;
            });
    });
</script>
</body>
</html>
